cmake_minimum_required(VERSION 3.16)

project(kylin-compile-env-builder LANGUAGES CXX)

set(TOP_PROJECT_NAME ${PROJECT_NAME})
file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" PROJECT_VERSION)

## Options
option(TRANSLATION_EMB          "Embedded .qm files for translations" ON)
option(TRANSLATION_GEN          "Generate .ts files for translations" OFF)
option(DISABLE_QT_CFA           "Disables automatic conversions from char* to QStrings" ON)

## Debug options
option(ENABLE_FTRACE            "Enable 'FUNCTION_TRACE' MACRO" ON)
option(ENABLE_FTRACE_FILEINFO   "Enable 'FUNCTION_TRACE' output with file info" OFF)
option(ENABLE_DEBUG_TRANSLATOR  "Enable debug message for translator" OFF)
option(ENABLE_DEBUG_PLUGINSMGR  "Enable debug message for PluginsManager" OFF)
option(ENABLE_DEBUG_TASK        "Enable debug message for Task and TaskManager" OFF)

## Compilation options
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(DISABLE_QT_CFA)
    add_definitions(-DQT_NO_CAST_FROM_ASCII)
endif()

if(ENABLE_FTRACE)
    add_definitions(-DDEBUG_FTRACE)
    if(ENABLE_FTRACE_FILEINFO)
        add_definitions(-DDEBUG_FTRACE_FILE_FUNC)
    endif()
    if(ENABLE_DEBUG_TRANSLATOR)
        add_definitions(-DDEBUG_TRANSLATOR)
    endif()
    if(ENABLE_DEBUG_PLUGINSMGR)
        add_definitions(-DDEBUG_PLUGINSMGR)
    endif()
    if(ENABLE_DEBUG_TASK)
        add_definitions(-DENABLE_DEBUG_TASK)
    endif()
endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
find_package(PkgConfig REQUIRED)

## Global Environment
include(cmake/environment.cmake)

## Output Project Information
message("--------------------------------------------")
message("Project: ${PROJECT_NAME} - v${PROJECT_VERSION}")
message("Options:")
message("    Qt Version: ${QT_VERSION}")
message("    Exec File: ${INSTALL_BIN_PATH}")
message("    Support Languages: ${LINGUAS}")
message("Translation Options:")
message("    Embedded Translations: ${TRANSLATION_EMB}")
message("    Generate Translations: ${TRANSLATION_GEN}")
message("    Translation Path Prefix: ${TRANSLATION_PATH_PREFIX}")
message("    Translation Path: ${TRANSLATION_PATH}")
message("Installation Options:")
message("    INSTALL_BIN_DIR: ${INSTALL_BIN_DIR}")
message("    INSTALL_LIB_DIR: ${INSTALL_LIB_DIR}")
message("    INSTALL_PLUGINS_DIR: ${INSTALL_PLUGINS_DIR}")
message("    INSTALL_ASSETS_DIR: ${INSTALL_ASSETS_DIR}")
message("    INSTALL_TRANSLATIONS_DIR: ${INSTALL_TRANSLATIONS_DIR}")
message("--------------------------------------------")

## Main application
include(cmake/application.cmake)

## Sub Projects
add_subdirectory(utility)
add_subdirectory(plugins)
